#include <iostream>
#include <algorithm>
#include <stack>

struct xy { int x, y, z; };

struct sh { int x, p; };

bool operator<(sh const & a, sh const & b)
{
	return a.x < b.x;
}

int const inf = 1<<25;
int const maxn = 5002;
int f[maxn][maxn];
xy path[maxn][maxn];
sh shelter[maxn];
int team[maxn];
int out[maxn];
int n, m;

void print()
{
	int y = m;
	for (int i = n; i > 0; i--) {
		out[i] = path[i][y].z;
		y = path[i][y].y;
	}
	std::cout << shelter[out[1]].p;
	for (int i = 2; i <= n; i++)
		std::cout << ' ' << shelter[out[i]].p;
	std::cout << '\n';
}

int main()
{
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> n;
		for (int i = 1; i <= n; i++) std::cin >> team[i];
		std::cin >> m;
		for (int i = 1; i <= m; i++) {
			std::cin >> shelter[i].x;
			shelter[i].p = i;
		}

		std::sort(team+1, team+n+1);
		std::sort(shelter+1, shelter+m+1);

		f[1][1] = std::abs(team[1] - shelter[1].x);
		path[1][1].z = 1;
		for (int i = 2; i <= n; i++) {
			for (int j = 1; j <= std::min(i, m); j++) {
				f[i][j] = inf;
				if (i > j) {
					f[i][j] = f[i-1][j] + std::min(std::abs(team[i] - shelter[j].x),
										std::abs(team[i] - shelter[j-1].x));
					path[i][j].x = i-1;
					path[i][j].y = j;
					path[i][j].z = j;
					if (f[i][j] == f[i-1][j] + std::abs(team[i] - shelter[j-1].x))
						path[i][j].z = j-1;
				}
				if (j > 1)
				if (f[i-1][j-1] + std::abs(team[i] - shelter[j].x) < f[i][j]) {
					f[i][j] = f[i-1][j-1] + std::abs(team[i] - shelter[j].x);
					path[i][j].x = i-1;
					path[i][j].y = j-1;
					path[i][j].z = j;
				}
			}
		}

		std::cout << f[n][m] << '\n';
		print();
	}
}

